using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using Spacejock;
using System;
using System.Collections;
using System.Reflection;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modWordUsageCount
	{
		public static void ShowWordUsageCount(clsProject cProject)
		{
			Collection colHash = new Collection();
			clsShared.cSubs.BusyMouse();
			try
			{
				IEnumerator enumerator = default(IEnumerator);
				try
				{
					enumerator = cProject.AllChaptersUsedNoInfoType().GetEnumerator();
					while (enumerator.MoveNext())
					{
						clsChapter clsChapter = (clsChapter)enumerator.Current;
						int sceneCount = clsChapter.SceneCount;
						for (int i = 1; i <= sceneCount; i++)
						{
							clsScene clsScene = cProject.get_SceneByID(clsChapter.get_SceneIDByIndex(i));
							if (!clsScene.Unused)
							{
								modWordcount.BreakAndHash(ref colHash, clsScene.ConvertedToPlainText());
								cDelay.RegularDoEvents();
							}
						}
					}
				}
				finally
				{
					if (enumerator is IDisposable)
					{
						(enumerator as IDisposable).Dispose();
					}
				}
				cDelay.RegularDoEvents();
				frmWordCount frmWordCount = new frmWordCount();
				frmWordCount.FillForm(colHash, WithSort: true);
				cDelay.RegularDoEvents();
				frmWordCount.ShowDialog();
				colHash.Clear();
			}
			catch (Exception ex)
			{
				ProjectData.SetProjectError(ex);
				Exception ex2 = ex;
				clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
				ProjectData.ClearProjectError();
			}
		}
	}
}
